package jjn.effective_java.chapter6.item34;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * @author Jiang Jining
 * @since 2023-04-26 23:18
 */
public enum CommandEnum {
    
    TY("推送指令"),
    NG("网管指令"),
    ZG("综合指令"),
    QT("其他指令");
    
    private final String displayName;
    
    CommandEnum(String displayName) {
        this.displayName = displayName;
    }
    
    public String getDisplayName() {
        return displayName;
    }
    
    public static final Map<String, String> stringToEnum =
            Stream.of(values()).collect(Collectors.toMap(CommandEnum::toString, CommandEnum::getDisplayName));
    
    public static String getTypeName(String commandNumber) {
        for (String prefix : stringToEnum.keySet()) {
            if (commandNumber.contains(prefix)) {
                return stringToEnum.get(prefix);
            }
        }
        return "";
    }
}
